package app.myproject.util;

import java.beans.PropertyEditorSupport;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class CustomeKeyEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String value) {
		if (value == null || value.length() == 0) {
			setValue(null);
		} else {
			setValue(KeyFactory.stringToKey(value));
		}
	}

	@Override
	public String getAsText() {
		Key value = (Key) getValue();
		return (value != null ? KeyFactory.keyToString(value) : "");
	}

}
